package com.offcn.controller;

import com.offcn.pojo.Demo;
import com.offcn.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

@Controller
public class DemoController {

    @Autowired(required=true)
    DemoService demoService;

    /**
     *
     * 添加实体demo，添加成功查询demo列表，
     * 转发到WEB-INF/jsp/demo.jsp页面上显示
     * @return
     */
    @RequestMapping(method=RequestMethod.POST,value="/saveDemo.action")
    public String saveDemo(Demo demo,Model model){
        demoService.saveDemo(demo);
        List<Demo> list = demoService.findDemoList();
        for (Demo d : list) {
            System.out.println(d);
        }
        model.addAttribute("list",list);
        return "list";
    }

    /**
     * 访问WEB-INF/jsp/index.jsp
     * @return
     */
    @RequestMapping(value="/index")
    public String index(){
        System.out.println("进入/jsp/demo.jsp");
        return "demo";
    }


}
